import { request } from '@/plugins/request'

// 获取公共的文章列表
export const getArticles = (params) => {
    return request({
      method: 'GET',
      url: '/api/articles',
      params
    })
}

// 获取关注的文章列表
export const getFeedArticles = (params) => {
  return request({
    method: 'GET',
    url: '/api/articles/feed',
    params
  })
}

// 获取文章详情
export const getArticle = slug => {
  return request({
    method: 'GET',
    url: `/api/articles/${slug}` 
  })
}

// 添加点赞
export const addFavorite = (slug) => {
  return request({
    method: 'POST',
    url: `/api/articles/${slug}/favorite`

  })
}

// 取消点赞
export const deleteFavorite = (slug) => {
  return request({
    method: 'DELETE',
    url: `/api/articles/${slug}/favorite`

  })
}

// 获取文章评论
export const getComments = slug => {
  return request({
    method: 'GET',
    url: `/api/articles/${slug}/comments`
  })
}
// 关注作者
export const followUser = username => {
  return request({
    method: 'POST',
    url: `/api/profiles/${username}/follow`
  })
}

// 取关作者
export const unFollowUser = username => {
  return request({
    method: 'DELETE',
    url: `/api/profiles/${username}/follow`
  })
}

// 添加评论
export const addComment = (slug, data) => {
  return request({
    method: 'post',
    url: `/api/articles/${slug}/comments`,
    data
  })
}

// 删除评论
export const deleteComment = (slug, id) => {
  return request({
    method: 'delete',
    url: `/api/articles/${slug}/comments/${id}`
  })
}

// 删除文章
export const deleteArticle = slug => {
  return request({
    method: 'delete',
    url: `/api/articles/${slug}`
  })
}
